package ui.face {

	import com.greensock.loading.ImageLoader;
	
	import common.loader.BaseLoader;
	import common.loader.LoaderManager;
	import common.loader.LoaderType;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import globals.Global;
	
	import ui.component.Label;
	
	import util.ColorUtil;
	import util.DisplayUtil;
	
	public class FriendCell extends Sprite {
		
		private var nameLabel:Label;
		private var icon:Bitmap;
		private var iconFrame:Shape;
		private var imageLoader:BaseLoader;
		private var invite:Bitmap;

		public function FriendCell() {
			super();
			
			iconFrame = new Shape();
			iconFrame.graphics.lineStyle(2, ColorUtil.FONT_BROWN);
			iconFrame.graphics.drawRect(0, 0, 50, 50);
			iconFrame.x = 10;
			iconFrame.y = 22;
			
			icon = new Bitmap();
			icon.x = 12;
			icon.y = 24;
			
			nameLabel = new Label(12, 0xFFFFFF, false, "center", true);
			nameLabel.width = 54;
			nameLabel.x = 14;
			nameLabel.y = 68;
			
			invite = new Bitmap();
			invite.x = 4;
			invite.y = 6;
			addChild(invite);
		}
		
		public function update(image:String = "", name:String = ""):void {
			if (image == "" && name == "") {
				invite.bitmapData = Global.assetsManager.getAssetsAsBitmapData("invite");
			} else {
				invite.bitmapData = Global.assetsManager.getAssetsAsBitmapData("friend");
				LoaderManager.add(image, LoaderType.IMAGE, imageHandler);
				addChild(iconFrame);
				nameLabel.text = name;
				addChild(nameLabel);
			}
		}
		
		private function imageHandler(data:BitmapData):void {
			icon.bitmapData = data;
			addChild(icon);
		}
	}
}